package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.OrderBean;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.utils.TextCheckUtils;
import com.jucai.pppeiyouclient.view.activity.CommonH5Activity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Kuky on 2017-04-21.
 */

public class PendingOrderAdapter extends CommonRecyclerViewAdapter<OrderBean> {
    private static final String TAG = "PendingOrderAdapter : ";

    public PendingOrderAdapter(Context context, List<OrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(CommonHolder holder, final OrderBean orderBean) {
        holder.setImage(R.id.order_user_img, orderBean.getMember_avatar(), 60, 60);
        holder.setText(R.id.order_number, "订单编号：" + orderBean.getTorder_ordersn());

         if(!TextUtils.isEmpty(orderBean.getMember_realname())) {
            holder.setText(R.id.order_user_name, orderBean.getMember_realname());
        }else {
            // String temp = orderBean.getMember_realname();
            //temp = temp.substring(0, 3) + "****" + temp.substring(7, 11);
            holder.setText(R.id.order_user_name, orderBean.getMember_phone());
        }

        holder.setText(R.id.order_user_info, orderBean.getMember_sexual() + " " + orderBean.getMember_age() + "岁");
        holder.setText(R.id.order_start_time, "" + orderBean.getTorder_start_time());
        holder.setText(R.id.order_start_location, "" + orderBean.getTorder_start_point());
        holder.setText(R.id.order_state, orderBean.getStatus());
        if (!TextUtils.equals(orderBean.getStatus(),"查看详情")) {
            holder.setInvisible(R.id.order_arrow_right);
        }
        holder.setGone(R.id.order_state_str);
        holder.setGone(R.id.order_create_time);
        holder.setGone(R.id.order_end);

        holder.setOnclickListener(R.id.order_user_img, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HashMap<String, String> param = new HashMap<>();
                param.put("id", orderBean.getTorder_id());
                param.put("service", "Conductor_Order.getuserinfo");
                param.put("user_id", orderBean.getMember_id());

                CommonRequestNetData.getJsonObjectData(mContext, param, true, new CommonRequestNetData.JsonObjectCallBack() {
                    @Override
                    public void parseJsonObject(JSONObject jsonObject) {
                        LogUtils.e(TAG + "jsObj = " + jsonObject);
                        try {
                            String toUrl = jsonObject.getString("URL");
                            CommonH5Activity.startCommH5(mContext, 2, toUrl, null, orderBean.getTorder_id(), null);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_layout;
    }
}
